home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Business Assistant
/
Business Assistant.iso
/
checkb
/
nojcb
/
cbmain.inc
< prev
Wrap
Text File
|
1989-09-09
|
29KB
|
620 lines
/*----------------------------------------------------------------------------
* File: CBMAIN.INC (in Turbo C 1.5)
*
* Purpose: Provides functions and structures for CB.
*
* Author: Steven "Noji" Ratzlaff
*
* Date: 09 Sep 1989
*--------------------------------------------------------------------------*/
struct EntryPrompt
{
char msg[MSG_LEN];
char var[LINE_LIM];
} input[] =
{
{ "Check or Item:", 0 },
{ "Date:", 0 },
{ "Amount:", 0 },
{ "Purpose:", 0 },
0
};
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
struct Record /* record of each transaction */
{
int ind; /* index number of the record */
char check[INPUT_SP]; /* check number / xaction type */
char date[INPUT_SP]; /* date of transaction */
char amt[INPUT_SP]; /* amount */
char pur[MSG_LEN]; /* purpose of transaction */
char bal[INPUT_SP]; /* balance after transaction */
struct Record
*next; /* pointer to the next record */
} *head,
*tail,
*cur;
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
char *func_key[] =
{
"WordPerfect", /* F1 */
"DEP", /* F2 */
"VIS", /* F3 */
"UCC", /* F4 */
"Loan Payment", /* F5 */
"Food-4-Less", /* F6 */
"Albertsons", /* F7 */
"Dr. Myers", /* F8 */
"Visa Credit Payment", /* F9 */
"Tithing", /* F10 */
0
};
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
int nmonth[] =
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
char *month[] =
{
"XXX", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
/*--------------------------------------------------------------------------*/
main(argc, argv) /* CB */
int argc;
char **argv;
{
struct ffblk
block; /* structure of file attributes */
int yn = 0; /* yes or no? */
char *acct = *++argv, /* account file name */
filepath[MAX_PATH]; /* " " pathname */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
strcpy(filepath, CB_DIR); /* specify the directory of the path */
if (argc == 2)
{
beg_bal[0] = last_check[0] = '\0'; /* initialize all global variables */
for (yn = 0; yn < ELEMENTS; yn++)
input[yn].var[0] = '\0';
yn = 0;
head = tail = cur = NULL;
prompt = getenv("PROMPT");
strcat(filepath, strupr(acct));
strcat(filepath, ".CB");
if (findfirst(filepath, &block, 0) == 0) /* if the file exists */
transact(filepath, yn); /* transact business */
else
{
printf(" *** Account '%s' not found\n%s", acct,
" Create a new account? ");
while (yn != 'y' && yn != 'n')
yn = tolower(getch());
if (yn == 'y')
{
printf("\n Enter the beginning balance: ");
gets(beg_bal);
transact(filepath, yn);
}
}
} /* end of if (argc == 2) ... */
else
{
printf("%s\n\n", Version);
directory(FALSE); /* display the account directory */
}
return 0; /* successful completion */
} /* end of main() */
/*----------------------------------------------------------------------------
* before_date(): Determines whether date1 is chronologically before date2.
* Both dates must be properly formatted beforehand.
*--------------------------------------------------------------------------*/
int
before_date(date1, date2)
char *date1, /* the date to test */
*date2; /* the date in question */
{
char c_day1[INPUT_SP], /* the day string */
c_day2[INPUT_SP], /* " " " */
c_month1[INPUT_SP], /* " month " */
c_month2[INPUT_SP], /* " " " */
c_year1[INPUT_SP], /* " year " */
c_year2[INPUT_SP]; /* " " " */
long total1, /* the composite of date1 */
total2; /* " " " date2 */
int i_day1, /* the day number */
i_day2, /* " " " */
i_month1, /* " month " */
i_month2, /* " " " */
i_year1, /* " year " */
i_year2, /* " " " */
i; /* arbitrary counter */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
strncpy(c_day1, date1, 2); /* get the days */
strncpy(c_day2, date2, 2);
c_day1[2] = c_day2[2] = '\0';
i_day1 = atoi(c_day1);
i_day2 = atoi(c_day2);
strcpy(c_month1, date1); /* get the months */
strcpy(c_month2, date2);
for (i = 0; i < 3; i++)
{
c_month1[i] = c_month1[i + 3];
c_month2[i] = c_month2[i + 3];
}
c_month1[3] = c_month2[3] = '\0';
for (i = 1; i < 13; i++)
{
if (stricmp(c_month1, month[i]) == 0)
i_month1 = i;
if (stricmp(c_month2, month[i]) == 0)
i_month2 = i;
}
strcpy(c_year1, date1); /* get the years */
strcpy(c_year2, date2);
for (i = 0; i < 2; i++)
{
c_year1[i] = c_year1[i + 7];
c_year2[i] = c_year2[i + 7];
}
c_year1[2] = c_year2[2] = '\0';
i_year1 = atoi(c_year1);
i_year2 = atoi(c_year2);
total1 = (long) i_day1 + (long) i_month1 * 100L + (long) i_year1 * 10000L;
total2 = (long) i_day2 + (long) i_month2 * 100L + (long) i_year2 * 10000L;
return (total1 < total2);
} /* end of before_date() */
/*----------------------------------------------------------------------------
* clear_line(): Clears the line from the current cursor pos to the end.
*--------------------------------------------------------------------------*/
void
clear_line(xpos)
int xpos;
{
while (++xpos < 70)
printf(" ");
} /* end of clear_line() */
/*----------------------------------------------------------------------------
* directory(): Displays a directory listing by account names.
*--------------------------------------------------------------------------*/
void
directory(menucall)
int